<template>
  <div class="login">
    <div class="box">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input
            v-model="form.username"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            placeholder="请输入密码"
            v-model="form.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="info">重置</el-button>
          <el-button type="primary" @click="add">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    //登陆按钮
    add() {
      this.$axios.post("/login", this.form).then((res) => {
        console.log(res);
        if (res.data.meta.status == 200) {
          this.$message({
            message: "恭喜你,登录成功",
            type: "success",
          });
            localStorage.setItem('token', res.data.data.token)
        //  跳转首页
        this.$router.push('/index')
        } else {
            this.$message.error('登录失败，用户名或密码错误');
        }
      });
    },
  },
  created() {},
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
.login {
  display: flex;
  width: 100%;
  height: 100vh;
  background-color: #304c6b;
  justify-content: center;
  align-items: center;
}
.box {
  background-color: #fff;
  width: 400px;
  padding: 20px;
}
.el-button {
  float: right;
  margin-left: 10px;
}
</style>
